package ar.com.sectorwine.controllers;

import java.security.Principal;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Valid;
import javax.validation.Validator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import ar.com.sectorwine.dto.StockDTO;
import ar.com.sectorwine.dto.StockDTOMapper;
import ar.com.sectorwine.entities.Empresa;
import ar.com.sectorwine.entities.Stock;
import ar.com.sectorwine.services.EmpresasService;
import ar.com.sectorwine.services.StockService;
import ar.com.sectorwine.services.UsuarioService;
import excepciones.ExcepcionGeneral;

/**
 * Handles requests for the application home page.
 */
@Controller
@Transactional(propagation = Propagation.REQUIRES_NEW)
public class ReportesController {

	@Autowired
	private StockService stockService;
	@Autowired
	private UsuarioService usuarioService;
	@Autowired
	private Validator validator;
	@Autowired
	private StockDTOMapper stockDTOMapper;

	private static final Logger logger = LoggerFactory
			.getLogger(ReportesController.class);

	@RequestMapping(value = "reporte_interesados", method = RequestMethod.GET)
	public ModelAndView reporte(Locale locale, @RequestParam String id,
			Model model, Principal principal) {

		logger.info("Welcome home! the client locale is " + locale.toString());

		ModelAndView mav = new ModelAndView("reportes/reporte_interesados");

		Stock stock_buscado = stockService.getStock(id);
		Empresa empresa = stockService
				.obtenerEmpresaByStock(Long.parseLong(id));
		mav.addObject("stock", stock_buscado);
		mav.addObject("contacto", empresa);
		// stockService.registrarInteres(id, principal.getName());
		return mav;
	}

}